package org.red5.core;

import java.io.File;
import java.io.UnsupportedEncodingException;


import com.meevle.utilities.MD5HashCalculator;
import com.twmacinta.util.MD5;

public class ApplicationSettings {

	private String red5Root, contextPath, contextFullPath, streamsPath, tempStreamName, tempStreamFilename, serverUrl, regexUser, regexTrack, regexProject, regexGenre, regexInstrument, regexPassword, regexRatingTrackComment;
	
	private volatile static ApplicationSettings instance = null;
	
	private ApplicationSettings()
	{}
	
	public static ApplicationSettings getInstance () {
        if (instance == null)
        {
        	synchronized (ApplicationSettings.class)
        	{
        		if (instance == null) instance = new ApplicationSettings ();
			}
        }
        return instance;
    }
	
	/**
	 * 
	 * @return \Meevle
	 */
	public String getContextPath() {
		return contextPath;
	}

	public void setContextPath(String contextPath) {
		this.contextPath = contextPath.replace("/", File.separator);
	}
	
	/**
	 * 
	 * @return C:\servers\Red5
	 */
	public String getRed5Root()
	{
		return red5Root;
	}
	
	public void setRed5Root(String red5Root)
	{
		this.red5Root = red5Root.replace("/", File.separator);
	}
	
	/**
	 * 
	 * @return C:\servers\Red5\webapps\Meevle
	 */
	public String getContextFullPath() {
		return contextFullPath;
	}
	
	public void setContextFullPath(String contextFullPath) {
		this.contextFullPath = contextFullPath.replace("/", File.separator);
	}
	
	/**
	 * 
	 * @return \streams
	 */
	public String getStreamsPath() {
		return streamsPath;
	}
	
	public void setStreamsPath(String streamsPath) {
		this.streamsPath = streamsPath.replace("/", File.separator);
	}
	
	/**
	 * 
	 * @param username
	 * @return \streams\hash\temp
	 */
	public String getUserTempPath(String username)
	{
		return getStreamsPath() + File.separator + MD5HashCalculator.getInstance().getHash(username) + File.separator + "temp";
	}
	
	/**
	 * 
	 * @param username
	 * @return \streams\hash\temp
	 */
	public String getUserTempPathWithoutStreams(String username)
	{
		return File.separator + MD5HashCalculator.getInstance().getHash(username) + File.separator + "temp";
	}
	
	/**
	 * 
	 * @param username
	 * @return \streams\hash\tracks
	 */
	public String getUserTracksPath(String username)
	{
		return getStreamsPath() + File.separator + MD5HashCalculator.getInstance().getHash(username) + File.separator + "tracks";
	}
	
	/**
	 * 
	 * @param username
	 * @return \hash\tracks
	 */
	public String getUserTracksPathWithoutStreams(String username)
	{
		return File.separator + MD5HashCalculator.getInstance().getHash(username) + File.separator + "tracks";
	}
	
	/**
	 * 
	 * @param userName
	 * @param setName
	 * @return \hashedUserName\hashedSetName
	 */
	public String getUserSetPathWithoutStreams(String userName, String setName)
	{
		return File.separator + MD5HashCalculator.getInstance().getHash(userName) + File.separator + MD5HashCalculator.getInstance().getHash(setName);
	}
	
	/**
	 * 
	 * @param userName
	 * @param setName
	 * @return \streams\hashedUserName\hashedSetName
	 */
	public String getUserSetPath(String userName, String setName)
	{
		return getStreamsPath() + File.separator + MD5HashCalculator.getInstance().getHash(userName) + File.separator + MD5HashCalculator.getInstance().getHash(setName);
	}
	
	/**
	 * 
	 * @return temp
	 */
	public String getTempStreamName() {
		return tempStreamName;
	}
	
	public void setTempStreamName(String tempStreamName) {
		this.tempStreamName = tempStreamName;
	}
	
	/**
	 * 
	 * @return temp
	 */
	public String getTempStreamFilename() {
		return tempStreamFilename;
	}
	
	public void setTempStreamFilename(String tempStreamFilename) {
		this.tempStreamFilename = tempStreamFilename;
	}
	
	/**
	 * 
	 * @return http://localhost:5080
	 */
	public String getServerUrl() {
		return serverUrl;
	}

	public void setServerUrl(String serverUrl) {
		this.serverUrl = serverUrl;
	}

	/**
	 * 
	 * @return ^[a-zA-Z0-9-][a-zA-Z0-9_-]{3,19}
	 */
	public String getRegexUser() {
		return regexUser;
	}

	public void setRegexUser(String regexUser) {
		this.regexUser = regexUser;
	}

	/**
	 * 
	 * @return ^[a-zA-Z0-9-][a-zA-Z0-9_-]{3,49}
	 */
	public String getRegexSlot() {
		return regexTrack;
	}

	public void setRegexSlot(String regexTrack) {
		this.regexTrack = regexTrack;
	}

	/**
	 * 
	 * @return .{4,50}
	 */
	public String getRegexSet() {
		return regexProject;
	}

	public void setRegexSet(String regexProject) {
		this.regexProject = regexProject;
	}
	
	/**
	 * 
	 * @return ^[a-zA-Z0-9-][a-zA-Z0-9_-]{3,19}
	 */
	public String getRegexPassword() {
		return regexPassword;
	}
	
	public void setRegexPassword(String regexPassword) {
		this.regexPassword = regexPassword;
	}
	
	/**
	 * 
	 * @return [a-zA-Z0-9 _-]{1,50}
	 */
	public String getRegexRatingSlotComment() {
		return regexRatingTrackComment;
	}
	
	public void setRegexRatingSlotComment(String regexRatingTrackComment) {
		this.regexRatingTrackComment = regexRatingTrackComment;
	}
	
}
